home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-08-10 | 40.1 KB | 1,427 lines |
-
- // Exports:
- // - init()
- // - reset(which)
- // - process()
- // - Arthur
- // - doSkip()
- // - zoomwin()
- // - toggleLoop()
- // - setUrlVal()
- // - setDimVal()
- // - setHexVal()
- //
- // Callbacks:
- // - selectObject() (onmousedown)
- // - dragObject() (onmousemove)
- // - freeObject() (onmouseup)
-
- // Platform detection ------------------------------------------------------ //
-
- ns4 = (document.layers) ? true : false;
- // ie4 = (document.all) ? true : false;
-
- // called once page has loaded
- function init()
- {
- // Constants, Aliases -------------------------------------------------- //
-
- initFromSubs(); // get substitution globals
-
- // ranges //
- SRANGE = 255;
-
- S_HMIN = 56;
- S_HMAX = S_HMIN + SRANGE;
-
- CP_MAX = 2;
- CP_MIN = -CP_MAX;
- CP_RANGE = CP_MAX - CP_MIN;
-
- CA_MAX = 180;
- CA_MIN = -CA_MAX;
- CA_RANGE = CA_MAX - CA_MIN;
-
- LP_MAX = 20;
- LP_MIN = -LP_MAX;
- LP_RANGE = LP_MAX - LP_MIN;
-
- WIN_MAX = 999; // 3 digits
- WIN_MIN = 1;
-
- // other constants
- WIN_DFLT = 200;
- var VIEW_SITE = 'http://www.famous3d.com/viewer/'
- LOGO_IMG_TAG = '<img src="' + VIEW_SITE +
- 'images/viewer_logo.gif" width=90 height=90 alt="Logo">';
- INSTALL_IMG_TAG = '<img src="' + VIEW_SITE +
- 'images/installing.gif" width=150 height=72 alt="Installing">';
- ABOUT_LINK = VIEW_SITE + 'about.html';
- IE_LINK = 'http://www.microsoft.com/ie/';
- NS_LINK = 'http://home.netscape.com/';
-
- SKIP_BUT = ROOTDIR + '/images/skip.gif';
- SKIP_BUT_GS = ROOTDIR + '/images/skipgs.gif';
-
- BG_URL = '';
-
- DELAY_TM = 100;
-
- // also seen: size=1 color="#000000"
- FONT_VALS = 'face="verdana, san-serif" size=2';
- LPXY_DFLT = 1;
- LPZ_DFLT = 10;
-
- // docwrite
- CDW_OPEN = "document.write('";
- CDW_CLOSE = "\\n');\n";
-
- CDoc = parent.frames["code"].document;
- HDoc = parent.frames["head"].document;
- DDoc = parent.frames["code"].document; // was "dirs"
-
- // Globals ------------------------------------------------------------- //
-
- SelectedSlide = null;
- Idle = false;
- PrevHelp = null;
- Arthur = null;
- NeedArthurUpdate = false;
-
- // Checks -------------------------------------------------------------- //
-
- // check for Java and CSS (cf no Javascript warning in dirs.html)
- if (!checkJava())
- reportErr("WARNING: The famous3D Code Generator requires a " +
- "Java-enabled browser. Either your browser doesn't " +
- "support Java, or you have disabled it.", 'No Java');
- else if (!checkCss())
- reportErr("WARNING: The famous3D Code Generator requires a " +
- "CSS-enabled browser. Either your browser doesn't " +
- "support CSS, or you have disabled CSS.", 'No CSS');
-
- // Setup --------------------------------------------------------------- //
-
- // checkIdle vars //
- if (ns4)
- {
- loopcell = document.optionssection.document.options.loopcell;
- lockcell = document.optionssection.document.options.lockcell;
- skipButton = document.panel.document.skip;
- }
- else
- {
- loopcell = options.loopcell;
- lockcell = options.lockcell;
- skipButton = skip;
- }
-
- // Setup plugin frame //
- // do this ASAP -- cf Arthur global (aInit()), below.
- // needs checkIdle() vars initted
- makeArthur();
-
- // Callbacks //
- document.onmousedown = selectObject;
- // other callbacks now done only if selected
-
- if (ns4)
- document.captureEvents
- (Event.MOUSEUP | Event.MOUSEMOVE | Event.MOUSEDOWN);
-
- // Connect to UI //
- r_slide = newSlider('ColSlider', 'rslider',
- 'colorsection', 'color', 'redcell');
- g_slide = newSlider('ColSlider', 'gslider',
- 'colorsection', 'color', 'greencell');
- b_slide = newSlider('ColSlider', 'bslider',
- 'colorsection', 'color', 'bluecell');
-
- cpx_slide = newSlider('CPSlider', 'cpxslider',
- 'campossection', 'campos', 'cpxcell');
- cpy_slide = newSlider('CPSlider', 'cpyslider',
- 'campossection', 'campos', 'cpycell');
- cpz_slide = newSlider('CPSlider', 'cpzslider',
- 'campossection', 'campos', 'cpzcell');
-
- cax_slide = newSlider('CASlider', 'caxslider',
- 'camangsection', 'camang', 'caxcell');
- cay_slide = newSlider('CASlider', 'cayslider',
- 'camangsection', 'camang', 'caycell');
- caz_slide = newSlider('CASlider', 'cazslider',
- 'camangsection', 'camang', 'cazcell');
-
- lpx_slide = newSlider('LPSlider', 'lpxslider',
- 'litpossection', 'litpos', 'lpxcell');
- lpy_slide = newSlider('LPSlider', 'lpyslider',
- 'litpossection', 'litpos', 'lpycell');
- lpz_slide = newSlider('LPSlider', 'lpzslider',
- 'litpossection', 'litpos', 'lpzcell');
-
- hncell = newCell('locsection', 'loc', 'hncell');
- hURLcell = newCell('locsection', 'loc', 'hURLcell');
- sURLcell = newCell('locsection', 'loc', 'sURLcell');
- iURLcell = newCell('locsection', 'loc', 'iURLcell');
- bgURLcell = newCell('locsection', 'loc', 'bgURLcell');
- dimxcell = newCell('dimsection', 'dim', 'dimxcell');
- dimycell = newCell('dimsection', 'dim', 'dimycell');
- hexcell = newCell('colorsection', 'color', 'hexcell');
-
- // do as late as possible (we hope arthur has loaded)
- aInit();
- }
-
- function aInit()
- {
- if (!ns4)
- Arthur = HDoc.arthur; // HDoc.all.arthur
- else if (HDoc.embeds.length)
- {
- // NS4BUG: ns4 seems to increment embeds.length *before* the
- // embed's ready!
- if (Arthur == null)
- Arthur = 0; // this is rool ugly -- delay one more time.
- else
- Arthur = HDoc.embeds[0];
- // embeds[0] may fail noisily (and break)
- // embeds['arthur'] always fails
- // embeds.arthur always fails
- }
-
- if (Arthur)
- reset('all'); // set UI values
- else // failed -- try again after delay (ns4 only? -- embed done late)
- setTimeout("aInit()", DELAY_TM);
- }
-
- // class Slider: base class for all sliders
- function Slider(elmt, cell)
- {
- // this.elmt = elmt; // was dom
- this.cell = cell;
- this.offsetX = 0;
- if (elmt)
- this.initPos(elmt);
- }
- Slider.prototype.select = SlideSelect;
- Slider.prototype.reset = SlideReset;
- Slider.prototype.initPos = (ns4) ? nsInitPos : ieInitPos;
-
- // class ColSlider: colour slider
- function ColSlider(dom, cell)
- {
- this.parent(dom, cell);
- }
- ColSlider.prototype = new Slider;
- ColSlider.prototype.parent = Slider;
- ColSlider.prototype.drag = ColDrag;
- ColSlider.prototype.helptag = "BGColor";
- ColSlider.prototype.setval = ColSetVal;
-
- // class CASlider: camera angle slider
- function CASlider(dom, cell)
- {
- this.parent(dom, cell);
- }
- CASlider.prototype = new Slider;
- CASlider.prototype.parent = Slider;
- CASlider.prototype.drag = CADrag;
- CASlider.prototype.helptag = "CAng";
- CASlider.prototype.setval = CASetVal;
-
- // class CPSlider: camera position slider
- function CPSlider(dom, cell)
- {
- this.parent(dom, cell);
- }
- CPSlider.prototype = new Slider;
- CPSlider.prototype.parent = Slider;
- CPSlider.prototype.drag = CPDrag;
- CPSlider.prototype.helptag = "CPos";
- CPSlider.prototype.setval = CPSetVal;
-
- // class LPSlider: light position slider
- function LPSlider(dom, cell)
- {
- this.parent(dom, cell);
- }
- LPSlider.prototype = new Slider;
- LPSlider.prototype.parent = Slider;
- LPSlider.prototype.drag = LPDrag;
- LPSlider.prototype.helptag = "LPos";
- LPSlider.prototype.setval = LPSetVal;
-
- // Slider method
- // initialise position (netscape)
- function nsInitPos(elmt)
- {
- this.xpos = parseInt(elmt.left); // parseInt from "999px"
- this.ypos = parseInt(elmt.top);
- this.w = elmt.clip.width;
- this.h = elmt.clip.height;
- this.sty = elmt;
- }
-
- // Slider method
- // initialise position (msie)
- function ieInitPos(elmt)
- {
- this.xpos = elmt.offsetLeft;
- this.ypos = elmt.offsetTop;
- this.w = elmt.clientWidth;
- this.h = elmt.clientHeight;
- this.sty = elmt.style;
- }
-
- function checkIdle(idleUrl)
- {
- Idle = (idleUrl.substr(idleUrl.length - 3, 3) == "f3d");
- skipButton.src = (Idle) ? SKIP_BUT : SKIP_BUT_GS;
- return Idle;
- }
-
- // write contents of plugin frame
- function makeArthur()
- {
- var s_url1 = MOTION_URL;
- var s_url2 = null;
-
- if (checkIdle(IDLE_URL))
- {
- s_url1 = IDLE_URL;
- s_url2 = MOTION_URL;
- }
-
- var dimval = new Array(WIN_DFLT, WIN_DFLT);
- var cpval = new Array(0, 0, 0);
- var caval = new Array(0, 0, 0);
- var lpval = new Array(LPXY_DFLT, LPXY_DFLT, LPZ_DFLT);
-
- preview
- (HDoc, "arthur", s_url1, s_url2, MODEL_URL, BG_URL, dimval, "#000000",
- cpval, caval, lpval, loopcell.checked, lockcell.checked);
- }
-
- // copy values into arrays
- function valArrays(dimval, cpval, caval, lpval)
- {
- dimval[0] = dimxcell.value;
- dimval[1] = dimycell.value;
-
- cpval[0] = parseFloat(cpx_slide.cell.value, 2);
- cpval[1] = parseFloat(cpy_slide.cell.value, 2);
- cpval[2] = parseFloat(cpz_slide.cell.value, 2);
-
- caval[0] = cax_slide.cell.value;
- caval[1] = cay_slide.cell.value;
- caval[2] = caz_slide.cell.value;
-
- lpval[0] = parseFloat(lpx_slide.cell.value, 1);
- lpval[1] = parseFloat(lpy_slide.cell.value, 1);
- lpval[2] = parseFloat(lpz_slide.cell.value, 1);
- }
-
- // generate example code
- function process()
- {
- // NB: can't make valArrays do "new Array" as they don't come back...
- var dimval = new Array(2);
- var cpval = new Array(3);
- var caval = new Array(3);
- var lpval = new Array(3);
- valArrays(dimval, cpval, caval, lpval);
-
- var idle = checkIdle(iURLcell.value);
- if (NeedArthurUpdate)
- preview
- (HDoc, "arthur", sURLcell.value, iURLcell.value, hURLcell.value,
- bgURLcell.value, dimval, hexcell.value, cpval, caval, lpval,
- loopcell.checked, lockcell.checked);
- generate
- (hncell.value, sURLcell.value, iURLcell.value, hURLcell.value,
- bgURLcell.value, dimval, hexcell.value, cpval, caval, lpval,
- loopcell.checked, lockcell.checked, idle);
- if (NeedArthurUpdate)
- {
- NeedArthurUpdate = false;
- // cf: aInit() re: setarthur
- if (!ns4)
- Arthur = HDoc.arthur;
- else
- Arthur = HDoc.embeds[0];
- }
- }
-
- // FIXME: unify: Idle, checkIdle, url1/2, ...
-
- // Arthur loop
- function toggleLoop()
- {
- Arthur.setLooping(loopcell.checked);
- }
-
- function toggleLock()
- {
- Arthur.setLock(lockcell.checked);
- }
-
- // Arthur restart
- function doSkip()
- {
- if (Idle)
- {
- Arthur.loadUrl(MOTION_URL, true);
- Arthur.loadUrl(IDLE_URL, false);
- }
- }
-
- // code inputs validation error
- function valerr(msg)
- {
- reportErr(msg, 'Validation Error');
- }
-
- function reportErr(msg, title)
- {
- title = title || 'Error';
- var doc = CDoc; // better than DDoc
- doc.open(); // "text/html"
- codeWrite(doc, openhtmlCode(title));
- codeWrite(doc, openbodyCode(''));
- doc.write('<p><font size="+1" color=red><b>', msg, '</b></font></p>');
- codeWrite(doc, closehtmlCode());
- doc.close();
- }
-
- // check whether Java is on
- function checkJava()
- {
- return navigator.javaEnabled();
- }
-
- // check whether CSS is on
- function checkCss()
- {
- // check whether our special "div" id is usable.
- return (ns4) ? document.checkcss : checkcss;
- }
-
- // validate code inputs
- function validate(hnval, sURLval, iURLval, hURLval, bgURLval, dimval, hexval,
- cpval, caval, lpval, loopval, lockval)
- {
- if (!hnval)
- {
- valerr('The Name is invalid');
- return false;
- }
-
- if (bgURLval.length > 0 &&
- (bgURLval.indexOf('.jpg') == -1 ||
- (bgURLval.indexOf('http:/') == -1 &&
- bgURLval.indexOf('file:/') == -1)))
- {
- valerr('The Backdrop URL is invalid.\n<br>' +
- 'NB: The viewer will only accept JPEG (.jpg) image files.');
- return false;
- }
-
- if (sURLval.indexOf(".f3d") == -1 ||
- (sURLval.indexOf("http:/") == -1 &&
- sURLval.indexOf("file:/") == -1))
- {
- valerr('The StreamURL is invalid');
- return false;
- }
-
- var test;
- test = parseInt(dimval[0]);
- if (test != dimval[0] || test < WIN_MIN) // never? (setDimVal)
- {
- valerr('The Width is invalid');
- return false;
- }
-
- test = parseInt(dimval[1]);
- if (test != dimval[1] || test < WIN_MIN) // never? (setDimVal)
- {
- valerr('The Height is invalid');
- return false;
- }
-
- if (isNaN(cpval[0]) || isNaN(cpval[1]) || isNaN(cpval[2]))
- {
- valerr('The Camera Position is invalid');
- return false;
- }
-
- if (isNaN(caval[0]) || isNaN(caval[1]) || isNaN(caval[2]))
- {
- valerr('The Camera Angle is invalid');
- return false;
- }
-
- if (isNaN(lpval[0]) || isNaN(lpval[1]) || isNaN(lpval[2]))
- {
- valerr('The Light Source Position is invalid');
- return false;
- }
-
- return true;
- }
-
- // code lines for: open javascript
- function scriptOpenCode()
- {
- return new Array(
- '<script language="javascript">',
- '<!--'
- );
- }
-
- // code lines for: close javascript
- function scriptCloseCode()
- {
- // these dangerous unbroken
- return new Array(
- '//--' + '>',
- '<' + '/script>'
- );
- }
-
- // code lines for: noscript
- function noscriptCode()
- {
- // this isn't very helpful...
- return new Array(
- '<noscript>',
- '<h1>JavaScript is required for this page.</h1>',
- '</noscript>'
- );
- }
-
- // code lines for: examples
- function idleEgCode(sURL, iURL)
- {
- return new Array
- ('<' + '!-- an example button --' + '>',
- '<a href="javascript:reloadF3D',
- ' (\'' + sURL + '\',',
- ' \'' + iURL + '\')"',
- ' >Click Here</a>');
- // 'document.' + hnval + '.loadUrl("sURL", "interrupt");'
- }
-
- function idleCodeComments(hnval)
- {
- return new Array
- ('<p>The following code should be put in the <head> section',
- 'of the HTML document that contains the stream.</p>',
-
- '<p><i>reloadF3D()</i> resets the stream playlist, and puts',
- 'the two streams (sURL, iURL) in the playlist. Also, the last',
- 'stream in the playlist will loop until interrupted.</p>',
-
- '<p><i>loadUrl()</i> is part of the famous3D viewer API.',
- 'eg: document.' + hnval + '.loadUrl("sURL", "interrupt");</p>',
-
- '<p><i>' + hnval + '</i> should be the name specified in the',
- '<object> tag\'s "ID" parameter, and/or the',
- '<embed> tag\'s "name" parameter.</p>',
-
- '<p><i>sURL</i> (string) should be an absolute URL for the motion',
- 'stream to be loaded.</p>',
-
- '<p><i>interrupt</i> (boolean) if true will stop playing the',
- 'current stream, empty the playlist, and start playing the new',
- 'stream immediately. If false, the viewer will add the stream to',
- 'the end of the playlist.</p>');
- }
-
- function idleCode(hnval)
- {
- return new Array
- ('function reloadF3D(sURL, iURL)',
- '{',
- ' document.' + hnval + '.loadUrl(sURL, true);',
- ' document.' + hnval + '.loadUrl(iURL, false);',
- ' document.' + hnval + '.setLooping(true);',
- '}');
- }
-
- // write code example to window for main/idle stream combo
- function genIdleCode(hnval, sURLval, iURLval)
- {
- CDoc.writeln('<p><b>Javascript for Multiple Streams</b></p>');
-
- // comments
- // NS4BUG: <table> convinces ns4 not to keep on applying div colour.
- CDoc.writeln('<table cellspacing=0 cellpadding=0 border=0><tr><td>');
- CDoc.writeln('<div style="color:blue;">');
- codeWrite(CDoc, idleCodeComments(hnval));
- CDoc.writeln('</td></tr></table></div>');
-
- // code
- CDoc.writeln('<pre>');
- codeEscWrite(CDoc, scriptOpenCode(), '');
- codeEscWrite(CDoc, idleCode(hnval), ' ');
- codeEscWrite(CDoc, scriptCloseCode(), '');
- codeEscWrite(CDoc, idleEgCode(sURLval, iURLval), '');
- CDoc.writeln('</pre>');
- }
-
- // generate the contents of the example code window
- function generate(hnval, sURLval, iURLval, hURLval, bgURLval, dimval, hexval,
- cpval, caval, lpval, loopval, lockval, idle)
- {
- if (!validate(hnval, sURLval, iURLval, hURLval, bgURLval, dimval, hexval,
- cpval, caval, lpval, loopval, lockval))
- return;
-
- source = (idle) ? iURLval : sURLval;
-
- CDoc.open();
- codeWrite(CDoc, openhtmlCode(''));
- codeWrite(CDoc, openbodyCode(''));
-
- if (idle)
- {
- genIdleCode(hnval, sURLval, iURLval);
- CDoc.writeln('<hr>');
- }
-
- // comments
- CDoc.writeln('<p><b>Javascript for embedding a stream</b></p>');
- CDoc.writeln('<p><font color=blue>The following code should be put in ',
- 'the <body> section of your web page.</font></p>');
-
- // start code
- CDoc.writeln('<p><pre>');
- codeEscWrite(CDoc, scriptOpenCode(), '');
-
- CDoc.writeln('bName = navigator.appName;');
- CDoc.writeln('bVer = parseInt(navigator.appVersion);');
- CDoc.writeln('hasPlugin = (navigator.plugins["Famous3D viewer"]) ? ',
- 'true : false;');
- CDoc.writeln('');
- CDoc.writeln('document.open();');
- CDoc.writeln('if (bName == "Microsoft Internet Explorer")');
- CDoc.writeln('{');
- CDoc.writeln(' if ((navigator.platform.indexOf("Win") != -1) &&');
- CDoc.writeln(' (navigator.platform.indexOf("Win16") == -1))');
- CDoc.writeln(' {');
-
- var code;
- code = ieViewCode(hnval, sURLval, hURLval, bgURLval, dimval, hexval,
- cpval, caval, lpval, loopval, lockval);
- codeDocWrite(CDoc, code, ' ');
-
- CDoc.writeln(' }');
- CDoc.writeln(' else');
- CDoc.writeln(' {');
-
- code = badPlatformCode();
- codeDocWrite(CDoc, code, ' ');
-
- CDoc.writeln(' }');
- CDoc.writeln('}');
- CDoc.writeln('else if (bName == "Netscape")');
- CDoc.writeln('{');
- CDoc.writeln(' if (hasPlugin)');
- CDoc.writeln(' {');
-
- code = nsViewCode(hnval, sURLval, hURLval, bgURLval, dimval, hexval,
- cpval, caval, lpval, loopval, lockval);
- codeDocWrite(CDoc, code, ' ');
-
- CDoc.writeln(' }');
- CDoc.writeln(' else');
- CDoc.writeln(' {');
- codeDocWrite(CDoc, dlPluginCode(dimval), ' ');
- CDoc.writeln(' }');
- CDoc.writeln('}');
- CDoc.writeln('else');
- CDoc.writeln('{');
-
- code = badBrowserCode();
- codeDocWrite(CDoc, code, ' ');
-
- CDoc.writeln('}');
- CDoc.writeln('document.close();');
- codeEscWrite(CDoc, scriptCloseCode(), '');
- CDoc.writeln('</pre></p>');
-
- // noscript (comments)
- CDoc.writeln('<p><font color=blue>This is used if the user does not ',
- 'have Javascript enabled in the browser. ',
- 'Put a version of your site that does not use Javascript ',
- 'here.</font></p>');
-
- // noscript (code)
- CDoc.writeln('<pre>');
- codeEscWrite(CDoc, noscriptCode(), '');
- CDoc.writeln('</pre>');
-
- // last comment
- CDoc.writeln('<p><font color=blue>For further assistance contact ',
- '<a href="mailto:support@famous3d.com">',
- 'support@famous3d.com</a></font></p>');
-
- codeWrite(CDoc, closehtmlCode(''));
- CDoc.close();
- }
-
- // code lines for: open html
- // nb: leaves trailing head... (cf openbodyCode)
- function openhtmlCode(title)
- {
- // some of these tags too dangerous to leave unbroken
- return new Array(
- '<' + 'html>',
- '<' + 'head>',
- '<title>' + title + '</title>'
- );
- }
-
- // code lines for: open body
- // nb: closes head, opens body (cf openhtml, closehtml)
- function openbodyCode(bodyargs)
- {
- // some of these tags too dangerous to leave unbroken
- return new Array(
- '<' + '/head>',
- '<' + 'body ' + bodyargs + '>'
- );
- }
-
- // code lines for: close html (and body: cf openhtml, openbody)
- function closehtmlCode()
- {
- return new Array(
- '<' + '/body>',
- '<' + '/html>'
- );
- };
-
- // generate our local page
- function preview(doc, hnval, s_url1, s_url2, hURLval, bgURLval, dimval, hexval,
- cpval, caval, lpval, loopval, lockval)
- {
- doc.open();
- codeWrite(doc, openhtmlCode(''));
- codeWrite(doc, openbodyCode(''));
- doc.writeln('<center>');
- var success = pluginPage(doc, hnval, s_url1, hURLval, bgURLval, dimval,
- hexval, cpval, caval, lpval, loopval, lockval,
- 'false');
- doc.writeln('</center>');
-
- codeWrite(doc, closehtmlCode());
- doc.close();
- }
-
- // generate a plugin page
- function pluginPage(doc, hnval, s_url, hURLval, bgURLval, dimval, hexval,
- cpval, caval, lpval, loopval, lockval, pause)
- {
- bName = navigator.appName;
- bVer = parseInt(navigator.appVersion);
- var success = true;
- var code;
- if (bName == "Microsoft Internet Explorer")
- {
- if (navigator.platform.indexOf("Win") != -1 &&
- navigator.platform.indexOf("Win16") == -1)
- {
- code = ieViewCode("arthur", s_url, hURLval, bgURLval, dimval,
- hexval, cpval, caval, lpval, loopval, lockval,
- pause);
- }
- else
- {
- code = badPlatformCode();
- success = false;
- }
- }
- else if (bName == "Netscape")
- {
- code = nsViewCode("arthur", s_url, hURLval, bgURLval, dimval, hexval,
- cpval, caval, lpval, loopval, lockval, pause);
- }
- else
- {
- success = false;
- code = badBrowserCode();
- }
- codeWrite(doc, code);
- return success;
- }
-
- // write lines of code (directly)
- function codeWrite(doc, code)
- {
- // 'join' is faster than iteration (?)
- doc.writeln(code.join('\n'));
- }
-
- // escape a line for writing
- function escapeStr(line)
- {
- // String.replace hopefully cheaper than us iterating over string
- var newline = line.replace(/</g, '<');
- newline = newline.replace(/>/g, '>');
- return newline;
- }
-
- // write lines of document.write() code
- function codeDocWrite(doc, code, indent)
- {
- // 'join' is faster than iteration (?)
- var joinstr = CDW_CLOSE + indent + CDW_OPEN;
- codeDocWriteLine(doc, code.join(joinstr), indent);
- }
-
- // write escaped lines of code
- function codeEscWrite(doc, code, indent)
- {
- if (!indent)
- indent = '';
- // 'join' is faster than iteration (?)
- codeEscWriteLine(doc, code.join('\n' + indent), indent);
- }
-
- // write a 'document.write(code)' line to doc (with indent)
- function codeDocWriteLine(doc, line, indent)
- {
- doc.write(indent, CDW_OPEN, escapeStr(line), CDW_CLOSE);
- }
-
- // write an escaped line of code to doc
- function codeEscWriteLine(doc, line, indent)
- {
- if (!indent)
- indent = '';
- doc.writeln(indent, escapeStr(line));
- }
-
- // code lines for: plugin under msie
- function
- ieViewCode(hnval, sURLval, hURLval, bgURLval, dimval, hexval, cpval, caval,
- lpval, loopval, lockval, pause)
- {
- pause = pause || 'false';
- return new Array
- ('<table width=' + dimval[0] + ' height=' + dimval[1] +
- ' cellpadding=0 cellspacing=0>', // bgcolor="#ffffff"
- '<tr valign=top><td width=0>', // 0 width -> good "installing" align
- // div style:"background-color:#ffffff;"
- '<div id="ielayer1" style="position:absolute; z-index:1;">',
- '<object id="' + hnval + '"',
- ' classid="CLSID:' + CLASSID + '"',
- ' codebase="' + CODEBASE + '"',
- ' width=' + dimval[0] + ' height=' + dimval[1] + '>',
- '<param name="bgcolor" value="' + hexval + '">',
- '<param name="streamURL" value="' + sURLval + '">',
- '<param name="headURL" value="' + hURLval + '">',
- '<param name="bgTextureURL" value="' + bgURLval + '">',
- '<param name="cameraPosition" value="' +
- cpval[0] + ' ' + cpval[1] + ' ' + cpval[2] + '">',
- '<param name="cameraRotation" value="' +
- caval[0] + ' ' + caval[1] + ' ' + caval[2] + '">',
- '<param name="lightPosition" value="' +
- lpval[0] + ' ' + lpval[1] + ' ' + lpval[2] + '">',
- '<param name="loop" value="' + loopval + '">',
- '<param name="cameraLock" value=' + lockval + '">',
- '<param name="pause" value="' + pause + '">',
- '',
- '<table cellpadding=5><tr><td>', // bgcolor="#ffffff"
- LOGO_IMG_TAG,
- '<font ' + FONT_VALS + '>',
- '<br>The famous3D viewer failed to install.',
- '<br><br>Refresh the page if you wish to retry installing, or',
- // a color="#0000ff"
- '<a href="' + ABOUT_LINK + '" target="_blank">click here</a>',
- 'to find out more about the famous3D Viewer</font>',
- '</td></tr></table>',
- '</object>',
- '</div></td>',
- '',
- // NB: this code simply sits *behind* the plugin...
- // FIXME: this code will break w/out CSS...
- '<td>' + INSTALL_IMG_TAG,
- '<font ' + FONT_VALS + '>',
- '<br>Installing Famous3D Viewer',
- '<br>Please Wait...</font>',
- '</td></tr>',
- '</table>');
- }
-
- // code lines for: bad platform
- function badPlatformCode()
- {
- return new Array
- ('<div align="center">',
- LOGO_IMG_TAG,
- '<font ' + FONT_VALS + '>',
- '<br>The famous3D Viewer only works on the Windows platform.',
- 'Sorry.</font>',
- '</div>');
- }
-
- // code lines for: download plugin
- function dlPluginCode(dimval)
- {
- return new Array
- // bgcolor="#0000ad" width=300 height=300
- ('<table width=' + dimval[0] + ' height=' + dimval[1] + '>',
- '<tr valign=middle><td align=center>',
- '<a href="' + PLUGINSPAGE + '" target="_blank">',
- LOGO_IMG_TAG,
- '</a></td></tr></table>');
- }
-
- // code lines for: plugin under netscape
- function
- nsViewCode(hnval, sURLval, hURLval, bgURLval, dimval, hexval, cpval, caval,
- lpval, loopval, lockval, pause)
- {
- pause = pause || 'false';
- return new Array
- ('<embed src="' + sURLval + '"',
- ' width=' + dimval[0] + ' height=' + dimval[1],
- ' name="' + hnval + '"',
- ' pluginspage="' + PLUGINSPAGE + '"',
- ' bgcolor="' + hexval + '"',
- ' headURL="' + hURLval + '"',
- ' bgTextureURL="' + bgURLval + '"',
- ' loop="' + loopval + '"',
- ' cameraLock="' + lockval + '"',
- ' pause="' + pause + '"',
- ' cameraPosition="' + cpval[0] +' '+ cpval[1] +' '+ cpval[2] + '"',
- ' cameraRotation="' + caval[0] +' '+ caval[1] +' '+ caval[2] + '"',
- ' lightPosition="' + lpval[0] +' '+ lpval[1] +' '+ lpval[2] + '">',
- '</embed>');
- }
-
- // code lines for: bad browser
- function badBrowserCode()
- {
- return new Array
- ('<p align="center">',
- LOGO_IMG_TAG,
- '<font ' + FONT_VALS + '>',
- '<br>This site requires the use of Microsoft Internet Explorer 4.0',
- 'or above; or Netscape Navigator 4.0 or above',
- '(excluding Netscape 6.0).',
- '<br>Please use one of these browsers to view famous3D animations...',
- 'or download them.</font></p>',
- '<ul>',
- ' <li><font ' + FONT_VALS + '>',
- '<a href="' + NS_LINK + '">Click here</a>',
- ' to get the latest version of Netscape Navigator.</font></li>',
- ' <li><font ' + FONT_VALS + '>' +
- '<a href="' + IE_LINK + '">Click here</a>',
- ' to get the latest version of',
- ' Microsoft Internet Explorer.</font></li>',
- '</ul>');
- }
-
- // Slide method
- function SlideSelect(x, y)
- {
- if (x > this.xpos && x < this.xpos + this.w &&
- y > this.ypos && y < this.ypos + this.h)
- {
- helpme(this.helptag);
- return this;
- }
- return null;
- }
-
- // selection
- function selectObject(e)
- {
- var x = (ns4) ? e.pageX : (event.x + document.body.scrollLeft);
- var y = (ns4) ? e.pageY : (event.y + document.body.scrollTop);
-
- SelectedSlide =
- r_slide.select(x, y) ||
- g_slide.select(x, y) ||
- b_slide.select(x, y) ||
-
- cpx_slide.select(x, y) ||
- cpy_slide.select(x, y) ||
- cpz_slide.select(x, y) ||
-
- cax_slide.select(x, y) ||
- cay_slide.select(x, y) ||
- caz_slide.select(x, y) ||
-
- lpx_slide.select(x, y) ||
- lpy_slide.select(x, y) ||
- lpz_slide.select(x, y);
-
- if (SelectedSlide)
- {
- document.onmousemove = dragObject;
- document.onmouseup = freeObject;
- SelectedSlide.offsetX = x - SelectedSlide.xpos;
- }
- }
-
- // drag slider
- function dragVal(e, slide)
- {
- var x = (ns4) ? e.pageX : (event.x + document.body.scrollLeft);
- var MoveToX = x - slide.offsetX;
- if (MoveToX < S_HMIN)
- MoveToX = S_HMIN;
- if (MoveToX > S_HMAX)
- MoveToX = S_HMAX;
-
- slide.xpos = MoveToX;
- slide.sty.left = MoveToX;
- }
-
- // Slider method
- function ColDrag(e)
- {
- dragVal(e, this);
- refreshColorCells();
- }
-
- // Slider method
- function CPDrag(e)
- {
- dragVal(e, this);
- var val = CP_MIN + (CP_RANGE * (this.xpos - S_HMIN) / SRANGE);
- this.cell.value = format(val, 2);
- moveCamPos();
- }
-
- // Slider method
- function CADrag(e)
- {
- dragVal(e, this);
- var val = CA_MIN + (CA_RANGE * (this.xpos - S_HMIN) / SRANGE);
- val = parseInt(val);
- if (isNaN(val))
- val = 0;
- this.cell.value = val;
- moveCamAng();
- }
-
- // Slider method
- function LPDrag(e)
- {
- dragVal(e, this);
- var val = LP_MIN + (LP_RANGE * (this.xpos - S_HMIN) / SRANGE);
- this.cell.value = format(val, 1);
- moveLightPos();
- }
-
- // drag slider
- function dragObject(e)
- {
- if (SelectedSlide)
- SelectedSlide.drag(e);
- }
-
- // update hex, plugin from colour sliders
- function refreshColorCells()
- {
- // Colour Cells
- var red = r_slide.xpos - S_HMIN;
- var green = g_slide.xpos - S_HMIN;
- var blue = b_slide.xpos - S_HMIN;
-
- r_slide.cell.value = red;
- g_slide.cell.value = green;
- b_slide.cell.value = blue;
-
- var hexred = red.toString(16);
- var hexgreen = green.toString(16);
- var hexblue = blue.toString(16);
-
- if (hexred.length == 1)
- hexred = "0" + hexred;
- if (hexgreen.length == 1)
- hexgreen = "0" + hexgreen;
- if (hexblue.length == 1)
- hexblue = "0" + hexblue;
-
- hexcode = "#" + hexred + hexgreen + hexblue;
- hexcell.value = hexcode.toUpperCase();
-
- if (ns4)
- document.colorproof.bgColor = hexcode;
- else
- colorproof.style.backgroundColor = hexcode;
-
- Arthur.setBgColorHex(hexcode);
- }
-
- // update slider from value
- function setOffset(slider, offset)
- {
- if (offset < 0 || isNaN(offset))
- offset = 0;
- if (offset > SRANGE)
- offset = SRANGE;
- offset += S_HMIN;
- slider.xpos = offset;
- slider.sty.left = offset;
- }
-
- // Slider method
- function ColSetVal(value, noupdate)
- {
- var offset = parseInt(value);
- setOffset(this, offset);
- if (!noupdate)
- refreshColorCells();
- }
-
- // Slider method
- function CPSetVal(value, noupdate)
- {
- var offset = SRANGE * (parseFloat(value) - CP_MIN) / CP_RANGE;
- setOffset(this, offset);
- if (!noupdate)
- moveCamPos();
- }
-
- // Slider method
- function CASetVal(value, noupdate)
- {
- var offset = SRANGE * (parseInt(value) - CA_MIN) / CA_RANGE;
- setOffset(this, offset);
- if (!noupdate)
- moveCamAng();
- }
-
- // Slider method
- function LPSetVal(value, noupdate)
- {
- var offset = SRANGE * (parseFloat(value) - LP_MIN) / LP_RANGE;
- setOffset(this, offset);
- if (!noupdate)
- moveLightPos();
- }
-
- function setDimVal(cell)
- {
- var value = parseInt(cell.value);
- if (isNaN(value))
- cell.value = WIN_DFLT;
- else if (value < WIN_MIN)
- cell.value = WIN_MIN;
- else if (value > WIN_MAX)
- cell.value = WIN_MAX;
- else
- cell.value = value;
-
- if (cell.oldval != cell.value)
- {
- NeedArthurUpdate = true;
- cell.oldval = cell.value;
- }
- }
-
- function setUrlVal(cell)
- {
- var value = cell.value;
-
- // var i = value.length - 1;
- // for ( ; value.charAt(i) != "/" && i > 0; i--)
- // ;
- // hURLcell.value = value.substr(0, i);
- // if (cell == iURLcell)
- // iURLcell.value = value.substr(0, i);
-
- if (cell.oldval != cell.value)
- {
- NeedArthurUpdate = true;
- cell.oldval = cell.value;
- }
- }
-
- function setHexVal(cell)
- {
- var value = cell.value;
-
- if (value.length == 6 && value.substr(0, 1) != "#")
- {
- value = "#" + value;
- cell.value = value;
- }
-
- if (value.length > 7)
- {
- value = "#000000";
- cell.value = value;
- }
-
- var hexred = value.substr(1, 2);
- var hexgreen = value.substr(3, 2);
- var hexblue = value.substr(5, 2);
-
- red = parseInt(hexred, 16);
- green = parseInt(hexgreen, 16);
- blue = parseInt(hexblue, 16);
-
- if (isNaN(red))
- {
- red = 0;
- value = "00" + value.substr(3, 4);
- cell.value = value;
- }
-
- if (isNaN(green))
- {
- green = 0;
- value = value.substr(0, 2) + "00" + value.substr(5, 2);
- cell.value = value;
- }
-
- if (isNaN(blue))
- {
- blue = 0;
- value = value.substr(0, 4) + "00";
- cell.value = value;
- }
-
- setOffset(r_slide, red);
- setOffset(g_slide, green);
- setOffset(b_slide, blue);
-
- refreshColorCells();
- }
-
- // update plugin from UI
- function moveCamPos()
- {
- var fx = parseFloat(cpx_slide.cell.value);
- var fy = parseFloat(cpy_slide.cell.value);
- var fz = parseFloat(cpz_slide.cell.value);
- Arthur.setCameraPosition(fx, fy, fz);
- }
-
- // update plugin from UI
- function moveCamAng()
- {
- var fx = parseFloat(cax_slide.cell.value);
- var fy = parseFloat(cay_slide.cell.value);
- var fz = parseFloat(caz_slide.cell.value);
- Arthur.setCameraRotation(fx, fy, fz);
- }
-
- // update plugin from UI
- function moveLightPos()
- {
- var fx = parseFloat(lpx_slide.cell.value);
- var fy = parseFloat(lpy_slide.cell.value);
- var fz = parseFloat(lpz_slide.cell.value);
- Arthur.setLightPosition(fx, fy, fz);
- }
-
- // done interaction
- function freeObject(e)
- {
- document.onmousemove = null;
- document.onmouseup = null;
- SelectedSlide = null;
- }
-
- // generate truncated floating point string
- function format(value, fp)
- {
- var pow = Math.pow(10, fp);
- return Math.round(value * pow) / pow;
- }
-
- // Slide method
- function SlideReset(val)
- {
- this.setval(val, 1); // set value with no update
- this.cell.value = val;
- }
-
- // reset values to defaults
- function reset(section)
- {
- if (section == "loc" || section == "all")
- {
- hncell.value = MODEL_NAME;
- sURLcell.value = MOTION_URL;
- iURLcell.value = IDLE_URL;
- hURLcell.value = MODEL_URL;
- bgURLcell.value = BG_URL;
- }
-
- if (section == "dim" || section == "all")
- {
- dimxcell.value = WIN_DFLT;
- dimycell.value = WIN_DFLT;
- }
-
- if (section == "color" || section == "all")
- {
- r_slide.reset(0);
- g_slide.reset(0);
- b_slide.reset(0);
- refreshColorCells(); // takes care of hex, too!
- }
-
- if (section == "campos" || section == "all")
- {
- cpx_slide.reset(0);
- cpy_slide.reset(0);
- cpz_slide.reset(0);
- moveCamPos();
- }
-
- if (section == "camang" || section == "all")
- {
- cax_slide.reset(0);
- cay_slide.reset(0);
- caz_slide.reset(0);
- moveCamAng();
- }
-
- if (section == "litpos" || section == "all")
- {
- lpx_slide.reset(LPXY_DFLT);
- lpy_slide.reset(LPXY_DFLT);
- lpz_slide.reset(LPZ_DFLT);
- moveLightPos();
- }
- }
-
- // help text for UI
- function helpme(help_index)
- {
- if (PrevHelp == help_index)
- return;
- PrevHelp = help_index;
-
- var title = null;
- var msg = null;
- if (help_index == "name")
- {
- title = 'Name';
- msg = '\t The name refers to the name of the object so that it ' +
- 'can be referenced to by your javascript.\n<br><br>' +
- '\t It is recommended that this variable has a meaningful name ' +
- 'such as the name of your character.';
- }
- if (help_index == "streamURL")
- {
- title = 'StreamURL (Motion URL)';
- msg = '\t StreamURL is the absolute path to your stream eg ' +
- 'http://www.arthur.com/streams/arthur.f3d';
- }
- if (help_index == "idleURL")
- {
- title = 'IdleURL';
- msg = '\t idleURL is the absolute path to your idle stream. ' +
- 'The idle stream will be looped at the begining and the end of ' +
- 'the main stream (specified above). There is additional code ' +
- 'added for a button to activate the main stream and play the ' +
- 'idle stream once it is complete.';
- }
- if (help_index == "headURL")
- {
- title = 'HeadURL (Model URL)';
- msg = '\t headURL is the absolute path to your head model, ' +
- 'usually this is the directory where your streams are being ' +
- 'stored eg http://www.arthur.com/streams';
- }
- if (help_index == "bgURL")
- {
- title = 'Background Texture URL';
- msg = '\t bgURL is the absolute path of a JPEG (.jpg) texture ' +
- 'to be used as a background image in the viewer.';
- }
- if (help_index == "Dim")
- {
- title = 'Dimension';
- msg = '\t Enter the height and width that you wish your head ' +
- 'to be. The standard size is about ' + WIN_DFLT + 'x' + WIN_DFLT +
- ' pixels.';
- }
- if (help_index == "BGColor")
- {
- title = 'Background Colour';
- msg = '\t You can use the sliders to get a colour. You can ' +
- 'also enter the Red Green and Blue (0 - 255) values in the ' +
- 'boxes along side the sliders or enter a Hex value in the box ' +
- '(#000000 - #FFFFFF) and finetune the colour with the sliders.';
- }
- if (help_index == "CPos")
- {
- title = 'Camera Position';
- msg = '\t Use the sliders to move the head around or specify a ' +
- 'unit in the fields above the sliders.<br> The edges of the box ' +
- 'are between +/- 1. The allowed range is between +/- ' + CP_MAX +
- ' units.';
- }
- if (help_index == "CAng")
- {
- title = 'Camera Angle';
- msg = '\t The Camera angle is Specified in Degrees around each ' +
- 'axis, You can use the sliders to adjust this value or specify ' +
- 'values in the boxes above the sliders. The allowed range is ' +
- 'between +/- ' + CA_MAX + ' degrees.';
- }
- if (help_index == "LPos")
- {
- title = 'Light Source Position';
- msg = '\t Lighting Position is a lot like Camera Position. The ' +
- 'allowed range for values is +/- ' + LP_MAX + ' units.';
- }
- if (help_index == "gen")
- {
- title = 'The Script';
- msg = '\t Now you can cut and paste the generated script into ' +
- 'your page and make minor adjustments. The script will detect ' +
- 'whether the user has the plugin and automatically or direct ' +
- 'them to a site where they can install the plugin.';
- }
-
- if (title)
- {
- DDoc.open();
- codeWrite(DDoc, openhtmlCode(title));
- codeWrite(DDoc, openbodyCode(''));
- DDoc.writeln('<b>', title, '</b>');
- DDoc.writeln('<table cellspacing=0 cellpadding=3>');
- DDoc.writeln('<tr><td>', msg, '</td></tr>');
- DDoc.writeln('</table>');
- codeWrite(DDoc, closehtmlCode());
- DDoc.close();
- }
- }
-
- function fullCellName(section, form, cellname)
- {
- if (ns4)
- return 'document.' + section + '.document.' + form + '.' + cellname;
- else
- return form + "." + cellname;
- }
-
- function newCell(section, form, cellname)
- {
- // NB: eval() can crash early NS -- test?
- return eval(fullCellName(section, form, cellname));
- }
-
- function newSlider(sliderType, sliderName, section, form, cellname)
- {
- fullslidername = (ns4) ? 'document.' + sliderName : sliderName;
- // NB: eval() can crash early NS -- test?
- return eval('new ' + sliderType + '(' + fullslidername + ', ' +
- fullCellName(section, form, cellname) + ');');
- }
-